package com.ruoyi.web.controller.system;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.PageQuery;
import com.ruoyi.common.utils.Result;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.sys.SysOssConfig;
import com.ruoyi.system.service.sys.SysOssConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 对象存储配置控制器
 * 前端访问路由地址为:/system/ossConfig
 *
 * @author seeTools
 * @date 2024-01-20 15:28:53
 */
@Validated
@RestController
@RequestMapping("/ossConfig")
public class SysOssConfigController {

    @Resource
    private SysOssConfigService sysossconfigService;

    /**
     * 查询对象存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss:list')")
    @PostMapping("/list")
    public Result<Page<SysOssConfig>> list(@RequestBody PageQuery<SysOssConfig> pageQuery) {
        Page<SysOssConfig> pageInfo = sysossconfigService.findList(pageQuery);
        return Result.success(pageInfo);
    }

    /**
     * 导出对象存储配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:oss:export')")
    @Log(title = "对象存储配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOssConfig model, HttpServletResponse response) {
        List<SysOssConfig> list = sysossconfigService.selectDataList(model);
        ExcelUtil<SysOssConfig> util = new ExcelUtil<SysOssConfig>(SysOssConfig.class);
        util.exportExcel(response, list, "对象存储配置数据");
    }

    /**
     * 获取对象存储配置详细信息
     *
     * @param ossConfigId 主键
     */
    @PreAuthorize("@ss.hasPermi('system:oss:query')")
    @GetMapping("/{ossConfigId}")
    public Result<SysOssConfig> getInfo(@PathVariable Long ossConfigId) {
        return Result.success(sysossconfigService.getById(ossConfigId));
    }

    /**
     * 新增对象存储配置
     */
    @PreAuthorize("@ss.hasPermi('system:oss:add')")
    @Log(title = "对象存储配置", businessType = BusinessType.INSERT)
    @PostMapping()
    public Result<Void> add(@Validated @RequestBody SysOssConfig model) {
        return Result.state(sysossconfigService.save(model));
    }

    /**
     * 修改对象存储配置
     */
    @PreAuthorize("@ss.hasPermi('system:oss:edit')")
    @Log(title = "对象存储配置", businessType = BusinessType.UPDATE)
    @PutMapping()
    public Result<Void> edit(@Validated @RequestBody SysOssConfig model) {
        return Result.state(sysossconfigService.edit(model));
    }

    /**
     * 删除对象存储配置
     *
     * @param ossConfigIds 主键串
     */
    @PreAuthorize("@ss.hasPermi('system:oss:remove')")
    @Log(title = "对象存储配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ossConfigIds}")
    public Result<Void> remove(@PathVariable Long[] ossConfigIds) {
        return Result.state(sysossconfigService.removeBatchByIds(ossConfigIds));
    }

    /**
     * 修改默认状态
     *
     * @param sysOssConfig sysOssConfig
     * @return Void
     */
    @PreAuthorize("@ss.hasPermi('system:oss:edit')")
    @Log(title = "对象存储配置", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public Result<Void> changeStatus(@RequestBody SysOssConfig sysOssConfig) {
        return Result.state(sysossconfigService.changeStatus(sysOssConfig));
    }
}
